package netip;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

//包含端口:在InetAddress基础上+端口
public class InetSocketDemo01 {
    public static void main(String[] args) {
        InetSocketAddress address=new InetSocketAddress("localhost",9999);
        //address=new InetSocketAddress(InetAddress.getByName("127.0.0.1"),9999);//同上
        System.out.println(address.getAddress());//获取主机名/主机ip
        System.out.println(address.getHostName());//获取主机名
        System.out.println(address.getPort());//获取端口号
        System.out.println(address.getHostString());//获取主机名

    }
}
